package engine;

import model.Model;

/**
 * The glue/controller of the overall simulation.
 *
 * <p>It provides a {@link get} method so it may be used as a singleton within
 * the simulation model code.</p>
 *
 * @author Ricardo Cruz {@literal <ricardo.pdm.cruz@gmail.com>}
 * @since  2014-11-12
 */
public class Simulation
{
	private Simulation(int model) {
		Scheduler.reset();
		agents = new LayerAgents(Model.getModelLegend(model).length);
		fluids = new LayerFluids();
		Model.setup(model, agents, fluids);
	}

	public LayerFluids getFluidsLayer() {
		return fluids;
	}

	public LayerAgents getAgentsLayer() {
		return agents;
	}

	/**
	 * Creates a new running simulation.
	 * @param model
	 */
	public static Simulation create(int model) {
		return (singleton = new Simulation(model));
	}

	/**
	 * Gets a pointer to the current simulation.
	 * @return currently running simulation
	 */
	public static Simulation get() {
		return singleton;
	}

	//** internal

	private static Simulation singleton;
	private LayerAgents agents;
	private LayerFluids fluids;
}
